const { convertHtmlToDocxBuffer } = require('../src');

/**
 * 测试样式继承功能
 * 验证在没有行内样式的情况下，是否能通过getComputedStyle获取继承属性
 */

describe('样式继承功能测试', () => {
  it('should inherit basic styles correctly', async () => {
    // 测试1: 基本的样式继承（颜色、字体、大小）
    const html = `
      <html>
        <head>
          <style>
            .parent {
              color: blue;
              font-family: Arial;
              font-size: 16px;
              font-weight: bold;
            }
          </style>
        </head>
        <body>
          <div class="parent">
            <p>这是带有继承样式的文本</p>
            <span>这是带有继承样式的span</span>
          </div>
        </body>
      </html>
    `;
    
    const result = await convertHtmlToDocxBuffer(html);
    
    expect(result).toBeDefined();
    expect(result.buffer).toBeDefined();
    expect(result.warnings).toBeInstanceOf(Array);
    
    console.log('测试1: 基本样式继承 - 转换完成', { warnings: result.warnings });
  });
  
  it('should handle multi-level style inheritance', async () => {
    // 测试2: 多个层级的样式继承
    const html = `
      <html>
        <head>
          <style>
            .grandparent {
              color: red;
              font-family: "Times New Roman";
              font-size: 20px;
            }
            .parent {
              font-weight: bold;
              font-style: italic;
            }
          </style>
        </head>
        <body>
          <div class="grandparent">
            <div class="parent">
              <p>这是多层级继承样式的文本</p>
            </div>
          </div>
        </body>
      </html>
    `;
    
    const result = await convertHtmlToDocxBuffer(html);
    
    expect(result).toBeDefined();
    expect(result.buffer).toBeDefined();
    expect(result.warnings).toBeInstanceOf(Array);
    
    console.log('测试2: 多层级样式继承 - 转换完成', { warnings: result.warnings });
  });
  
  it('should prioritize inline styles over inherited styles', async () => {
    // 测试3: 内联样式优先于继承样式
    const html = `
      <html>
        <head>
          <style>
            .parent {
              color: green;
              font-family: Verdana;
              font-size: 18px;
            }
          </style>
        </head>
        <body>
          <div class="parent">
            <p style="color: purple; font-size: 24px;">这是带有内联样式的文本（应覆盖继承样式）</p>
            <p>这是继续使用继承样式的文本</p>
          </div>
        </body>
      </html>
    `;
    
    const result = await convertHtmlToDocxBuffer(html);
    
    expect(result).toBeDefined();
    expect(result.buffer).toBeDefined();
    expect(result.warnings).toBeInstanceOf(Array);
    
    console.log('测试3: 内联样式优先级 - 转换完成', { warnings: result.warnings });
  });
});